<!--
 * @Description: 订单分配弹窗
 * @Version: 1.0
 * @Author: Yuanjy
 * @Date: 2020-04-18 18:40:39
 * @LastEditors: Yuanjy
 * @LastEditTime: 2020-04-22 20:39:31
 -->
<template>
  <div class="div-inline">
    <el-button size="mini" type="success" @click="to">分配营养师</el-button>
    <el-dialog :visible.sync="dialog" :before-close="handleClose" title="营养师分配" width="450px" style="text-align:left;">
      <el-form :model="form" label-width="90px">
        <el-form-item label="营养师">
          <el-select v-model="form.principal" size="small" filterable placeholder="营养师选择" style="width:80%">
            <el-option v-for="item in principals" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="订单类型">
          <el-select v-model="form.order_type" size="small" placeholder="订单类型选择" style="width:80%">
            <el-option v-for="(item, index) in types" :key="index" :label="item" :value="index" />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog = false">取 消</el-button>
        <el-button type="primary" @click="commitDistribute">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import eForm from './form'

export default {
  components: { eForm },
  props: {
    supThis: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      dialog: false,
      form: {
        ids: [],
        principal: '',
        order_type: ''
      },
      principals: [],
      types: [],
    }
  },
  mounted() {
    this.initParams()
  },
  methods: {
    to() {
      if (this.$parent.originIds.length === 0) {
        this.$notify({ title: '提示', message: '请选择待分配的订单', type: 'error', duration: 2500 })
        return 
      }
      this.form.ids = this.$parent.originIds
      this.dialog = true
    },
    initParams() {
      //获取订单类型信息
      this.$api.order.service
        .params({
          params: { keys: ['types'] }
        })
        .then(res => {
          this.types = res.data.types
        }).catch(err => {
          console.log(err)
        })

      //获取当前管理员的部门成员信息
      this.$api.permission.user
        .getSubordinate()
        .then(res => {
          this.principals = res.data
        }).catch(err => {
          console.log(err)
        })
    },
    commitDistribute() {
      this.$api.order.origin
        .distribute({
          data: this.form
        })
        .then(res => {
          this.dialog = false
          this.$parent.init()
        }).catch(err => {
          console.log(err)
        })
      // api.GET(apiConfig.distribution, param, res => {
      //   this.distributeVisible = false
      //   this.$notify({
      //     message: '分配成功'
      //   })
      //   this.getOrderNumber()
      //   this.getList()
      // }, res => {
      //   this.$notify({
      //     message: res.msg
      //   })
      // })
    },
    handleClose() {
      this.distributeVisible = false
      this.multipleSelection = []
      this.principal = null
    },
  }
}
</script>

<style scoped>

</style>
